import request from '@/utils/request'
// import { otherFiltersItem } from '@/utils'
const appCode = 'order-center'
const domainCode = 'marketing'
/**
 * 根据字典类型批量查询字典值列表
 * @param {Array} dictTypeCodes 数据字典编码
 * @returns {Array} 数据字典值列表
 * */
export const getDictByTypeCode = async(dictTypeCodes) => {
  const res = await request({
    url: `/data-dict/api/v2/dictionary/patch/dictTypeCode`,
    method: 'post',
    params: { appCode, domainCode },
    data: dictTypeCodes
  })
  return res && res.data
}

// 品类
export function queryCategoryData(data) {
  return request({
    url: `/select-service/api/v1/productCategory/page`,
    method: 'post',
    data
  })
}

// 分配任务
export function submitAllocationTask(data) {
  return request({
    url: `/api/v1/productConfigTask`,
    method: 'put',
    data
  })
}

// 获取关联图纸
export function queryPicTableData(data) {
  return request({
    url: `/api/v1/shopDesignPicture/getPicture/page1`,
    method: 'post',
    data,
    headers: {
      'Permission-perCode': 'drawingsmanagement',
      'Permission-App': 'slm'
    }
  })
}

// 获取待变更的产品配置单
export function getTaskDetail(id) {
  return request({
    url: `/api/v1/productConfigTask/detail/${id}`,
    method: 'get'
  })
}

// 成品配置----获取出图品类及数量
export function getProOutpicCategory(data) {
  return request({
    url: `/api/v1/designOutpicDetailTask/getCategoryNumberPageByPicTaskCode`,
    method: 'post',
    data
  })
}

// 获取出图品类及数量
export function queryOutpicCategory(data) {
  return request({
    url: `/api/v1/designOutpicDetailTask/getCategoryNumberPageByPicTaskCode`,
    method: 'post',
    data
  })
}

// 新增产品配置单
export function submitConfigTable(data) {
  return request({
    url: `/api/v1/productConfigSheet`,
    method: data.configCode ? 'put' : 'post',
    data
  })
}

// 删除产品配置单
export function delConfigTable(data) {
  return request({
    url: `/api/v1/productConfigSheet/deleteBatch`,
    method: 'delete',
    data
  })
}

// 获取成品配置编辑数据
export function getProConfigEditData(id) {
  return request({
    url: `/api/v1/productConfigSheet/detail/${id}`,
    method: 'get'
  })
}

// 保存成品配置编辑数据
export function saveProConfigEditData(data) {
  return request({
    url: `/api/v1/productConfigSheet/configProduct`,
    method: 'put',
    data
  })
}

// 审核产品配置数据
export function auditConfigEditData(data) {
  return request({
    url: `/api/v1/productConfigSheet/examine`,
    method: 'post',
    data
  })
}

// 终止数据
export function stopData(data) {
  return request({
    url: `/api/v1/productConfigSheet/stops`,
    method: 'put',
    data
  })
}

// 变更产品配置附件---资源
export function changeFileList(data, modelId) {
  return request({
    url: `/api/v1/shopAttachment/batchUpdate`,
    method: 'put',
    data,
    params: { modelId }
  })
}

// 变更产品配置状态---资源
export function changeConfigState(data) {
  return request({
    url: `/api/v1/productConfigSheet/handles`,
    method: 'put',
    data
  })
}

// 获取产品上样推荐
export function getProRecommend(data, pageFlag, onlyCountFlag, filtersRaw) {
  return request({
    url: `/api/v1/configSampleRecommend/queryEndProRecommendModel`,
    method: 'post',
    data,
    params: { pageFlag, onlyCountFlag, filtersRaw }
  })
}

// 获取环境成品上样推荐
export function getEnvirProRecommend(data, pageFlag, onlyCountFlag, filtersRaw) {
  return request({
    url: `/api/v1/configSampleRecommend/queryAmbientRecommendModel`,
    method: 'post',
    data,
    params: { pageFlag, onlyCountFlag, filtersRaw }
  })
}

// 获取成品搭配上样推荐
export function getEndProMatch(data, page, rows, onlyCountFlag, filtersRaw) {
  return request({
    url: `/api/v1/configCollocationSample/queryEndProCollocationModel`,
    method: 'post',
    data,
    params: { page, rows, onlyCountFlag, filtersRaw }
  })
}

// 获取环境成品搭配上样推荐
export function getEnvironmentMatch(data, page, rows, onlyCountFlag, filtersRaw) {
  return request({
    url: `/api/v1/configCollocationSample/queryAmbientCollocationModel`,
    method: 'post',
    data,
    params: { page, rows, onlyCountFlag, filtersRaw }
  })
}

// 根据型号和品类获取产品
export function getProductList(data) {
  return request({
    url: `/api/v1/productConfigSheet/queryProductInfo`,
    method: 'post',
    data
  })
}

// 获取主数据产品
export function queryProductList(data) {
  return request({
    url: `/select-service/api/v1/productInfo/page`,
    method: 'post',
    data
  })
}

// 获取系列专区产品
export function queryBigStyleData(data) {
  return request({
    url: `/api/v1/configSeries/page`,
    method: 'post',
    data
  })
}

// 根据系列和品类获取产品
export function getProductListBysc(data) {
  return request({
    url: `/api/v1/productConfigSheet/sampleOptionalPage`,
    method: 'post',
    data
  })
}

// 获取型号----卫浴
export function getModelTableData(data) {
  return request({
    url: `/select-service/api/v1/productModel/page`,
    method: 'post',
    data
  })
}

// 获取产品---- 卫浴
export function queryProData(data) {
  return request({
    url: `/select-service/api/v1/productInfo/page`,
    method: 'post',
    data
  })
}

/**
 * 获取配置
 * @returns
 */
export function postConfigAttachmentTemplate(modelCode) {
  const obj = [{ 'id': 'belongModel', 'property': 'belongModel', 'operator': '=', 'value': modelCode }]
  const data = new FormData()
  data.append('filtersRaw', JSON.stringify(obj))
  // data.append('filtersRaw', JSON.stringify([otherFiltersItem('belongModel', modelCode, '=')]))
  console.log(modelCode)
  return request({
    url: '/api/v1/configAttachmentTemplate/page',
    method: 'POST',
    data
  })
}

// 附件下载
export function exportFile(url, data) {
  return request({
    url: url,
    method: 'post',
    data,
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 获取产品配置人员
export function queryConfigurator(data) {
  return request({
    url: `/api/v1/configPersonnelAndOffice/page`,
    method: 'post',
    data
  })
}

// 获取产品配置单
export function queryConfigSheet(data, code) {
  return request({
    url: `/api/v1/productConfigSheet/page`,
    method: 'post',
    data,
    headers: {
      'Permission-Percode': code, 'Permission-App': 'slm'
    }
  })
}

/**
 *
 * @param {FormData} data
 * @returns
 */
export function searchProductCodes(data) {
  return request({
    url: `/select-service/api/v1/productInfo/page`,
    method: 'post',
    data
  })
}

/**
 饰品配置清单批量删除
 */
export function deleteOrnamentList(data) {
  return request({
    url: `/api/v1/productConfigDetailedList/deleteBatch`,
    method: 'delete',
    data
  })
}
